const UserFeedback = require('../model/userFeedback.model')


class UserFeedbackService {
    /**
     * 创建反馈
     */
    async createFeedback (FeedbackData) {
        // 插入数据
        try {
            const res = await UserFeedback.create(FeedbackData)
            return res
        } catch (error) {
            return {
                errorFlag: 'error',
                errorCode: error.parent.code,
                message: error.parent.sqlMessage,
            }
        }
    }

    /**
     * 获取反馈列表
     */
    async getFeedbackList ({ act_id, is_handled, user_account }) {
        const whereOpt = {}
        // 短路运算 值存在就拷贝进whereOpt
        act_id && Object.assign(whereOpt, { act_id })
        is_handled && Object.assign(whereOpt, { is_handled })
        user_account && Object.assign(whereOpt, { user_account })
        const res = await UserFeedback.findAll({ where: whereOpt })
        return res
    }

    /**
     * 处理活动反馈
     */
    async handleFeedback (handleData, feedback_id) {
        try {
            const res = await UserFeedback.update(handleData, { where: { feedback_id } })
            return res
        } catch (error) {
            return {
                errorFlag: 'error',
                message: error,
            }
        }
    }
}

module.exports = new UserFeedbackService()